package com.lagou.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.lagou.annotation.MyComponent;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.Properties;

@MyComponent("druidUtil")
public class DruidUtil {
    private DruidDataSource ds = new DruidDataSource();

    public DruidUtil(){
        Properties properties = new Properties();
        InputStream resourceAsStream = DruidUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
        try {
            properties.load(resourceAsStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
        ds.setDriverClassName(properties.getProperty("jdbc.driver"));
        ds.setUrl(properties.getProperty("jdbc.url"));
        ds.setUsername(properties.getProperty("jdbc.username"));
        byte[] decode = Base64.getDecoder().decode(properties.getProperty("jdbc.password"));
        ds.setPassword(new String(decode));
    }

    public  DruidDataSource getDruidDataSource(){
        return ds;
    }

}
